package example.step2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class PrimarySerial {

    public static void main(String args[]) throws Exception {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\primary.obj"));
        // 针对Boolean数据的序列化
        out.writeBoolean(true);
        out.writeBoolean(false);
        // 针对Short的序列化
        out.writeShort(32);
        // 针对Int的序列化
        out.writeInt(32);
        // 针对Long的序列化
        out.writeLong(32L);
        // 针对Char的序列化
        out.writeChar('a');
        // 针对Byte的序列化
        out.writeByte(18);
        // 针对Float的序列化
        out.writeFloat(3.2f);
        // 针对Byte的序列化创建分割线：11
        out.writeByte(17);
        // 针对Double的序列化
        out.writeDouble(3.2);

        out.close();

        ObjectInputStream in = new ObjectInputStream(new FileInputStream(
                "E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\primary.obj"));
        // 数据的反序列化读取
//        System.out.println(in.readBoolean());
//        System.out.println(in.readBoolean());
//        System.out.println(in.readShort());
//        System.out.println(in.readInt());
        System.out.println(in.readLong());
        System.out.println(in.readLong());
        System.out.println(in.readChar());
        System.out.println(in.readByte());
        System.out.println(in.readFloat());
        System.out.println(in.readByte());
        System.out.println(in.readDouble());

        System.out.println(Long.toHexString(72057731476881440L));

        in.close();

    }
}